package com.authenticateCenter.service.impl;

import com.authenticateCenter.domain.entity.Role;
import com.authenticateCenter.domain.entity.RoleAuthority;
import com.authenticateCenter.mapper.RoleMapper;
import com.authenticateCenter.service.IRoleAuthorityService;
import com.authenticateCenter.service.IRoleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.common.mybaits.CustomPage;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 大忽悠
 * @since 2022年10月08日
 */
@Service
@RequiredArgsConstructor
@Transactional
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {
    private final RoleMapper roleMapper;

    @Override
    public List<Role> getRolesByUid(CustomPage customPage, Integer uid) {
        if(!CustomPage.enable(customPage)){
            return roleMapper.getRolesByUid(uid);
        }
        return roleMapper.getRolesByUidWithPage(uid,customPage);
    }

    @Override
    public void removeRole(Integer roleId, IRoleAuthorityService iRoleAuthorityService) {
        removeById(roleId);
        iRoleAuthorityService.remove(new QueryWrapper<RoleAuthority>().eq("rid",roleId));
    }
}
